﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class CommissionValueDataAccess : DataBase
    {
        private readonly string _baseSql = @"SELECT * FROM TB_COMMISSIONVALUE CV
JOIN TB_GAMETYPE GT ON GT.GAMEID=CV.GAMEID
JOIN TB_COMPANYTYPE CT ON CT.ID=CV.COMPANYTYPEID";

        public void InsertCommission(CommissionValue commission)
        {
            string sql = string.Format(@"INSERT INTO {0} ({1},{2},{3},{4},{5}) VALUES (@{1},@{2},@{3},@{4},@{5})",
                CommissionValue.TABLENAME, CommissionValue.COMMISSIONID, CommissionValue.GAMEID,
                CommissionValue.COMPANYTYPEID, CommissionValue.COMM, CommissionValue.ODDS);
            object id = base.ExecuteScalar(sql, new SqlParameter(CommissionValue.COMMISSIONID, commission.CommissionId),
                new SqlParameter(CommissionValue.GAMEID, commission.GameType.GameId),
                new SqlParameter(CommissionValue.COMPANYTYPEID, commission.CompanyType.Id),
                new SqlParameter(CommissionValue.COMM, commission.Comm),
                new SqlParameter(CommissionValue.ODDS, commission.Odds));
        }
        public void DeleteCommission(int commissionId)
        {
            string sql = string.Format(@"DELETE {0} WHERE {1}=@{1}", CommissionValue.TABLENAME, CommissionValue.COMMISSIONID);
            base.ExecuteNonQuery(sql, new SqlParameter(CommissionValue.COMMISSIONID, commissionId));
        }

        public IList<CommissionValue> GetCommValues(int commissionId)
        {
            string sql = string.Format(@"{0} WHERE CV.{1}=@{1}", _baseSql, CommissionValue.COMMISSIONID);
            return base.ExecuteList<CommissionValue>(sql, new SqlParameter(CommissionValue.COMMISSIONID, commissionId));
        }
    }
}
